# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gettext

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.19.1
pkgrel=1
arch=('any')
groups=("${MINGW_PACKAGE_PREFIX}")
pkgdesc="GNU internationalization library (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-libiconv") # "${MINGW_PACKAGE_PREFIX}-termcap"
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-ncurses")
options=('strip' 'staticlibs')
license=('GPL' 'LGPL')
url="http://www.gnu.org/software/gettext/"
source=("http://ftp.gnu.org/pub/gnu/${_realname}/${_realname}-$pkgver.tar.gz"{,.sig}
        00-relocatex-libintl-0.18.3.1.patch
        120-Fix-Woe32-link-errors-when-compiling-with-O0.patch
        04-mingw-script-slash-fix.mingw.patch
        05-always-use-libintl-vsnprintf.mingw.patch
        06-dont-include-ctype-after-gnulibs-wctype.mingw.patch
        07-fix-asprintf-conflict.mingw.patch)
md5sums=('8949a57e82abe88274a93174ade515e4'
         'SKIP'
         '91921076ca88a28db98af7189408f469'
         '6fc5459e5afa3f9df7602fcd1d09355b'
         '0f754bf438368854ef63886715a3b023'
         '27852a388b8cf38188dc392c244230ff'
         'f69747f43f279b8a81286cfe5916b82f'
         '3ebccf730ec3377b068027eb2283afb2')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
  patch -p1 -i ${srcdir}/00-relocatex-libintl-0.18.3.1.patch
  patch -p0 -i ${srcdir}/04-mingw-script-slash-fix.mingw.patch
  patch -p0 -i ${srcdir}/05-always-use-libintl-vsnprintf.mingw.patch
  patch -p0 -i ${srcdir}/06-dont-include-ctype-after-gnulibs-wctype.mingw.patch
  patch -p0 -i ${srcdir}/07-fix-asprintf-conflict.mingw.patch
  #patch -p1 -i ${srcdir}/120-Fix-Woe32-link-errors-when-compiling-with-O0.patch
  
  # libtoolize --automake --copy --force
  # ./autogen.sh --quick --skip-gnulib
}

build()
{
  CFLAGS+=" -D__USE_MINGW_ANSI_STDIO=1 -fexceptions --param=ssp-buffer-size=4"
  CXXFLAGS+=" -D__USE_MINGW_ANSI_STDIO=1 -fexceptions --param=ssp-buffer-size=4"

  mkdir -p $srcdir/build-${MINGW_CHOST} && cd $srcdir/build-${MINGW_CHOST}
  # export lt_cv_deplibs_check_method='pass_all'
  ${srcdir}/${_realname}-$pkgver/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --disable-java \
    --disable-native-java \
    --disable-csharp \
    --enable-static \
    --enable-threads=win32 \
    --without-emacs \
    --disable-openmp \
    --without-cvs \
    --without-git \
    --with-included-libcroco \
    --with-included-libunistring \
    --with-included-libxml \
    --with-included-glib \
    --with-libncurses-prefix=${MINGW_PREFIX}
  make
}

package() {
  cd $srcdir/build-${MINGW_CHOST}
  make DESTDIR="$pkgdir" install
}
